﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebAPI使用Nlog日志示例.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class NlogDemoController : ControllerBase
    {
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="logger"></param>
        public NlogDemoController(ILogger<NlogDemoController> logger)
        {
            Logger = logger;
        }

        /// <summary>
        /// 保存日志对象
        /// </summary>
        public ILogger<NlogDemoController> Logger { get; }

        /// <summary>
        /// 测试日志
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Test()
        {
            Logger.LogInformation("测试日志");
            Logger.LogError("测试错误日志");
            Logger.LogDebug("测试调试日志");
            Logger.LogWarning("测试警告日志");

            return Ok("WebAPI使用Nlog日志示例完成，请在Bin/Debug/net8.0/目录下查看日志文件");
        }
    }
}
